
function tbHandler (exception) {
    fullMessage = exception.name + ': ' + exception.message;
    uri = exception.fileName;
    stack = exception.stack;

    // Firefox sometimes blows up here
    line = exception.lineNumber   ;                     
    msg = "<pre>" + fullMessage + "\n" + uri + ": Line " + line + "</pre>\n";
    webpage = "\r\n<h1>Powster Unhandled Error</h1>" + msg;
    return webpage;
}


function PowsterMan() {
    // A manager for different powster applications

    var url = "file:///Users/paul/sandboxes/roadster/trunk/studio";
    addIncludePath(url);
    include("hello", "PowsterApp");
    this.powsterapps = {};
    var now = new Date();
    this.startuptime = now.getTime();
    
    this.logdata = [
    [0, "Startup"],
    ];
    document.getElementById('my-tree').view = mytreeView;
}

var mytreeView = {
    rowCount : 1,
    getCellText : function(row,column){
        var logdata = pow_server.powsterman.logdata.reverse();
        thismsg = logdata[row];
        if (column.id == "timecol") return thismsg[0];
        else return thismsg[1];
    },
    setTree: function(treebox) { 
        this.treebox = treebox;
        },
    isContainer: function(row){ return false; },
    isSeparator: function(row){ return false; },
    isSorted: function(){ return false; },
    getLevel: function(row){ return 0; },
    getImageSrc: function(row,col){ return null; },
    getRowProperties: function(row,props){},
    getCellProperties: function(row,col,props){},
    getColumnProperties: function(colid,col,props){}
};



PowsterMan.prototype.loadApps = function() {
    // Browse for ini files and load apps

    this.logDebug("Entering loadApps");

    // XXX temporary hack, need to make auto-launch of 
    // the studio a preference

//    window.openDialog('chrome://pow/content/powster/studio.xul', 
//    						'Roadster Studio', 		
//    						'chrome,titlebar,toolbar,centerscreen,resizable', this);    
    this.powsterapp = new PowsterApp();
}

PowsterMan.prototype.logDebug = function (msg) {
    var now = new Date();
    var msgtime = now.getTime() - this.startuptime;
    this.logdata.push([msgtime, msg]);
    var tree = document.getElementById("my-tree");
    var boxobject = tree.boxObject;
    boxobject.QueryInterface(Components.interfaces.nsITreeBoxObject);
    boxobject.invalidate();
    boxobject.rowCountChanged(0, 1);
    //tree.view['rowCount'] = tree.view['rowCount'] + 1;
}

PowsterMan.prototype.getApp = function () {
    // Given an app key, return the app.  The app is defined 
    // outside the pow.jar file

    return this.powsterapp;
}


PowsterMan.prototype.reloadApp = function () {
    JSModule.reload("hello");
    JSModule.include("hello", "PowsterApp");
    this.powsterapp = new PowsterApp();
}

function runEval () {
    try {
        var cmd = document.getElementById("rsinterpreter").value;
        var result = eval(cmd);
    } catch (e) {
        var result = e.fileName+" "+e.lineNumber+": "+e.message;    
    }
    var rlb = document.getElementById("interpreteroutput");
    rlb.insertItemAt(0, result);
}

